/**
* Copyright 2012 nabla
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
*/
package com.nabla.wapp.client.ui;

import java.util.Iterator;

import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.nabla.wapp.client.general.Assert;


public class Menu extends com.smartgwt.client.widgets.menu.Menu implements HasWidgets {

	private String		title;
	private String		icon;

	public Menu() {}

	@Override
	public void add(Widget w){
		if (w instanceof Menu) {
			final Menu m = (Menu)w;
			final com.smartgwt.client.widgets.menu.MenuItem proxy = new com.smartgwt.client.widgets.menu.MenuItem(w.getTitle());
			proxy.setSubmenu(m);
			proxy.setTitle(m.getTitle());
			proxy.setIcon(m.getIcon());
			addItem(proxy);
		} else {
			Assert.state(w instanceof IMenuItem<?>);
			this.addItem(((IMenuItem<?>)w).getImpl());
		}
	}

	@Override
	public void clear() {}

	@Override
	public Iterator<Widget> iterator() {
        return null;
	}

	@Override
	public boolean remove(@SuppressWarnings("unused") Widget w) {
        return false;
	}

	@Override
	public void setTitle(final String title) {
		this.title = title;
	}

	@Override
	public String getTitle() {
		return title;
	}

	public void setIcon(final String icon) {
		this.icon = icon;
	}

	public String getIcon() {
		return icon;
	}
}
